﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;

namespace Jbe.TestSuite.Help.Presentation
{
    public class BindableWebBrowser : DockPanel
    {
        public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source", typeof(Uri),
            typeof(BindableWebBrowser), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(SourceChangedHandler)));


        private readonly WebBrowser webBrowser;


        public BindableWebBrowser()
        {
            webBrowser = new WebBrowser();
            Children.Add(webBrowser);
        }


        public WebBrowser WebBrowser { get { return webBrowser; } }

        public Uri Source
        {
            get { return (Uri)GetValue(SourceProperty); }
            set { SetValue(SourceProperty, value); }
        }


        private static void SourceChangedHandler(DependencyObject source, DependencyPropertyChangedEventArgs e)
        {
            BindableWebBrowser bindableWebBrowser = (BindableWebBrowser)source;
            bindableWebBrowser.WebBrowser.Source = (Uri)e.NewValue;
        }
    }
}
